package com.ylxin.smartplatform.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.ylxin.smartplatform.constans.ResultCode;

/**
 * @author 29048
 * @version V1.0
 * @Project smartplatform
 * @Package com.ylxin.smartplatform.dto
 * @Description: 数据传递对象 —— 精简对象(从数据库中返回的部分列，不至于把数据库中对应的整张表都创建出对应的类，况且数据库中有些数据是不显示的，上次登录时间，这次登录时间
 * 上次登录IP 这次登录IP)
 * Create by 杨立新 @Date 2022/9/5 16:37
 */
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class R {
    private int code;
    private String msg;
    private Object data;

    public static R OK(){
        return OK(null);
    }

    public static R OK(Object data){
        return getResult(ResultCode.SUCCESS,"成功", data);
    }


    public static R ERROR(){
        return ERROR(null);
    }

    public static R ERROR(Object data){
        return getResult(ResultCode.FAIL,"失败", data);
    }



    public static R getResult(int code, String msg){
        return getResult(code,msg,null);
    }

    public static R getResult(int code, String msg, Object data){
        R r = new R();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }



    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
